<template>
<div>
  <city-header></city-header>
  <city-search :cities='cities'></city-search>
  <city-list
    :cities='cities'
    :hot='hotcities'
    :letter='letter'
  ></city-list>
  <city-alphabet
    :cities='cities'
    @change='handleLetterChange'
  ></city-alphabet>
</div>
</template>

<script>
import axios from 'axios'
import CityHeader from './components/Header'
import CitySearch from './components/Search'
import CityList from './components/List'
import CityAlphabet from './components/Alphabet'
export default {
  name: 'City',
  components: {
    CityHeader,
    CitySearch,
    CityList,
    CityAlphabet
  },
  data () {
    return {
      cities: {},
      hotcities: [],
      letter: ''
    }
  },
  methods: {
    getCityInfo () {
      axios.get('/api/city.json').then(this.getCityInfoSucc)
    },
    getCityInfoSucc (res) {
      console.log(res.data)
      res = res.data
      if (res.ret && res.data) {
        const data = res.data
        this.hotcities = data.hotCities
        this.cities = data.cities
      }
    },
    handleLetterChange (letter) {
      this.letter = letter
      // console.log(letter)
    },
    getCity () {
      axios.get('http://route.showapi.com/107-32?showapi_appid=68470&showapi_sign=f73d20910c094dd1a5631fd6d3c5e2a5')
        .then(function (response) {
          console.log('res', response.data.showapi_res_body.list)
        })
        .catch(function (error) {
          console.log('err', error)
        })
    }
  },
  mounted () {
    this.getCityInfo()
    this.getCity()
  }
}
</script>

<style lang='stylus' scoped>

</style>
